package binaryTree;

import utils.binaryTreeUtil.TreeNode;

public class isValidBST {
    public boolean isValidBST(TreeNode root) {
        if (root.left == null && root.right == null) {
            return true;
        }
        return isValid(root, Long.MIN_VALUE, Long.MAX_VALUE);
    }

    public boolean isValid(TreeNode root,long down,long up) {
        if (root==null) {
            return true;
        }
        if (root.val<=down||root.val>=up) {
            return false;
        }
        return isValid(root.left, down, root.val)&&isValid(root.right, root.val, up);
    }

    public static void main(String[] args) {

    }
}
